package com.android.duininsuoai.adapt;

import android.graphics.Paint;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.duininsuoai.model.group.SortKillData;
import com.android.duininsuoai.utils.ObjectUtils;
import com.android.duininsuoai.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/8/10.
 */
public class MainListSortKillAdapt extends BaseQuickAdapter<SortKillData.SortXianshiData.ListBean, BaseViewHolder> {


    public MainListSortKillAdapt(int layoutResId, List<SortKillData.SortXianshiData.ListBean> data) {
        super(layoutResId, data);

    }

    @Override
    protected void convert(BaseViewHolder helper, SortKillData.SortXianshiData.ListBean listBean) {
        ((TextView) helper.getView(R.id.item_list_sort_kill_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        ObjectUtils.photo2(mContext, listBean.getThumb(), ((ImageView) helper.getView(R.id.item_list_sort_kill_img)));
        SpannableString msp = new SpannableString("￥" + listBean.getTeam_price());
        msp.setSpan(new AbsoluteSizeSpan(13, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        helper.setText(R.id.item_list_sort_kill_title, listBean.getName());
        helper.setText(R.id.item_list_sort_kill_after, msp);
        helper.setText(R.id.item_list_sort_kill_before, "￥" + listBean.getPrice());

        final int endtime = Integer.parseInt(listBean.getEnd_time());
        final int starttime = Integer.parseInt(listBean.getStart_time());
        final int run_time = listBean.getRun_time();

        if (run_time > endtime && run_time > starttime) {
            //活动结束
            helper.setVisible(R.id.item_list_sort_kill_start_ll, true);
            helper.setVisible(R.id.item_list_sort_kill_time, true);
            helper.setVisible(R.id.item_list_sort_kill_kai_ll, false);

            helper.setText(R.id.item_list_sort_kill_time, "活动已结束");
            helper.setText(R.id.item_list_sort_kill_start_tv, "活动已结束");
            helper.setBackgroundRes(R.id.item_list_sort_kill_start_tv, R.drawable.corner_gray_bg);

        } else if (run_time > starttime && run_time < endtime) {
            //拼团中   是否剩余
            helper.setVisible(R.id.item_list_sort_kill_start_ll, false);
            helper.setVisible(R.id.item_list_sort_kill_time, false);
            helper.setVisible(R.id.item_list_sort_kill_kai_ll, true);
            helper.setText(R.id.item_list_sort_kill_progress_tv, "已售：" + listBean.getScale() + "%");
            helper.setProgress(R.id.item_list_sort_kill_progress, listBean.getScale());

            if (listBean.getScale() == 100) {
                helper.setText(R.id.item_list_sort_kill_kai, "已被抢完");
                helper.setBackgroundRes(R.id.item_list_sort_kill_kai, R.drawable.corner_gray_bg);

            } else {
                helper.setText(R.id.item_list_sort_kill_kai, "立即抢购");
                helper.setBackgroundRes(R.id.item_list_sort_kill_kai, R.drawable.corner_red_bg);
                helper.addOnClickListener(R.id.item_list_sort_kill_kai_ll);
            }

        } else if (run_time < starttime) {
            //即将开始

            helper.setVisible(R.id.item_list_sort_kill_start_ll, true);
            helper.setVisible(R.id.item_list_sort_kill_time, true);
            helper.setVisible(R.id.item_list_sort_kill_kai_ll, false);

            String strendTime = ObjectUtils.getStrTime(listBean.getStart_time(), "MM月dd日 HH:mm");

            helper.setText(R.id.item_list_sort_kill_time, strendTime + "开抢");
            helper.setText(R.id.item_list_sort_kill_start_tv, "即将开始");
            helper.setBackgroundRes(R.id.item_list_sort_kill_start_tv, R.drawable.corner_kill_bg);

        }
    }


}
